package com.hq.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by He Zhijie on 2015/7/9.
 */
public class TimeUtil {
    public static final String TIME_PATTERN="yyyy-MM-dd HH:mm:ss";
    public static final String TIME_ZONE="GMT+8";
    public static Date getDbCurrentDate(){
        return new Date();
    }

    public static String getDbCurrentDateStr(){
        SimpleDateFormat df=new SimpleDateFormat(TIME_PATTERN);
        return df.format(getDbCurrentDate());
    }

    public static String getDbCurrentDateStr(String pattern){
        SimpleDateFormat df=new SimpleDateFormat(pattern);
        return df.format(getDbCurrentDate());
    }

    public static String formatDate(Date date){
        SimpleDateFormat df=new SimpleDateFormat(TimeUtil.TIME_PATTERN);
        return df.format(date);
    }

    public static String formatDate(Date date,String pattern){
        SimpleDateFormat df=new SimpleDateFormat(pattern);
        return df.format(date);
    }

    public static Date parseDateStr(String str) {
        SimpleDateFormat df=new SimpleDateFormat(TIME_PATTERN);
        try {
            return df.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args){
        System.out.println(formatDate(new Date(),"yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
    }
}
